class Solution(object):
    def findMiddleIndex(self, nums):
        n = len(nums)
        for i in range(n - 1):
            nums[i + 1] += nums[i]
        for i in range(n):
            if i == 0:
                left = 0
            else:
                left = nums[i - 1]
            right = nums[-1] - nums[i]
            if left == right:
                return i
        return -1